<?php
	$admin_info 		= new Zendvn_System_Info();
	$admin_info 		= $admin_info->getMemberInfo();
	//----------------------- INPUT ELEMENTS -------------------//
	$name 				= $this->formText ( 'name', $this->Item['name'], array ('class' => 'txtmedium') ) . '<div class="view_error" id="view_name"></div>';
	$slbKhoahoc			= $this->formSelect ( 'id_khoahoc', $this->Item['id_khoahoc'], array('style' => 'min-width:256px;'), $this->Khoahoc) . '<div class="view_error" id="view_id_khoahoc"></div>';
	$ngaykhaigiang		= $this->formText ( 'ngaykhaigiang', $this->Item['ngaykhaigiang'], array ( 'class' => 'txtshort hasDatePicker', 'title' => 'ngày / tháng / năm' ) ) . '<div class="view_error" id="view_ngaykhaigiang"></div>';
	$ngayketthuc		= $this->formText ( 'ngayketthuc', $this->Item['ngayketthuc'], array ( 'class' => 'txtshort hasDatePicker', 'title' => 'ngày / tháng / năm' ) ) . '<div class="view_error" id="view_ngayketthuc"></div>';
	
	$option 			= array('Không','Có');
	if(isset($this->Item['status'])){
		$trangthai 		= $this->Item['status'];
	}else{
		$trangthai 		= 1;
	}
	$status 			= $this->formRadio('status',$trangthai,null,$option, ' ');
	if(isset($this->Item['order'])){
		$order 			= $this->Item['order'];
	}else{
		$order 			= 255;
	}
	$order 				= $this->formText ('order', $order, array ('class' => 'txtshort' ) );
	$content 			= $this->cmsEditor('content',htmlspecialchars_decode($this->Item['content']),array('toolbar'=>'MyToolbar', 'language'=>'vi', 'skin' => 'v2'), 'auto', 200, true, 500, false);
	
	$optionTrangthai	= array('0' => 'Sắp khai giảng', '1' => 'Đang hoạt động', '2' => 'Đã kết thúc');
	$trangthai			= $this->formSelect ( 'trangthai', $this->Item['trangthai'], array('style' => 'min-width:256px;'), $optionTrangthai);
?>
<div class="left_content">
	<?php echo $this->render($this->arrParam['controller'] . '/toolbar/left.php');?>
</div>

<div class="right_content">
	<div class="appContent">
		<form action="" method="post" name="appForm">
			<?php echo $this->render($this->arrParam['controller'] . '/toolbar/index.php');?>
			<?php
				//-------------------- SESSAGES ERROR ------------------
				if(count($this->messageError)>0){
					foreach ($this->messageError AS $key => $val){
						echo '<div class="listError" data="'.$key.'" rel="' . $val . '"></div>';
					}
					echo '<div class="thongbaoError goc5">Có lỗi trong quá trình xử lý.</div>';
				} 
			?>
			<div id="tabs">
				<ul>
					<li><a href="#tabs-1">Thông tin chung</a></li>
					<li><a href="#tabs-2">Lịch học</a></li>
				</ul>
				<div id="tabs-1">
					<div class="tblForm">
						<div class="tbl_content">
							<table class="tbl">
								<tr>
									<td class="label">Tên lớp học <span class="red">*</span></td>
									<td><?php echo $name;?></td>
									
									<td class="label">Thứ tự</td>
									<td><?php echo $order;?></td>
								</tr>
								<tr>
									<td class="label">Chọn khóa học <span class="red">*</span></td>
									<td><?php echo $slbKhoahoc;?></td>
									
									<td class="label">Hiển thị</td>
									<td><?php echo $status;?></td>
								</tr>
								<tr>
									<td class="label">Trạng thái</td>
									<td><?php echo $trangthai;?></td>
								</tr>
								<tr>
									<td class="label">Chọn giáo viên</td>
									<td>
										<div class="divChonUser" id="divChonGiaoVien">
											<?php
											
											//echo $this->Item['id_giaovien'];die;
											if(!empty($this->Item['id_giaovien'])){
												$id_giaovien = $this->Item['id_giaovien'];
												if(!is_array($this->Item['id_giaovien'])){
													$id_giaovien = explode(',', $this->Item['id_giaovien']);
												}
												foreach ($id_giaovien AS $key => $val){
													$name_alias = $this->Users[$val]['name'];
													if($this->Users[$val]['alias'] != ''){
														$name_alias = $this->Users[$val]['name'] . ' (' . $this->Users[$val]['alias'] . ')';
													}
													echo '<span class="item goc3" id="'.$this->Users[$val]['id'].'" title="'.$this->Users[$val]['chucvu_name'].' - '.$this->Users[$val]['phongban_name'].'">'.$name_alias.'<a href="javascript:void(0)" class="delete" title="Xóa" onclick="xoaMotUser('.$this->Users[$val]['id'].', \'divChonGiaoVien\')"></a></span>';
													echo '<input id="'.$this->Users[$val]['id'].'" type="hidden" name="id_giaovien[]" value="'.$this->Users[$val]['id'].'">';
												}
											} 
											?>
										</div>
										<a onclick="showListUser('divChonGiaoVien', 'id_giaovien')" href="javascript:void(0)" class="showListUser" id="showListUser">Show</a>
										<a onclick="xoaTrangDiv('divChonGiaoVien')" href="javascript:void(0)" class="deleteListUser">Delete</a>
									</td>
								</tr>
								<tr>
									<td class="label">Chọn trợ giảng</td>
									<td>
										<div class="divChonUser" id="divChonTroGiang">
											<?php
											if(!empty($this->Item['id_trogiang'])){
												$id_trogiang = $this->Item['id_trogiang'];
												if(!is_array($this->Item['id_trogiang'])){
													$id_trogiang = explode(',', $this->Item['id_trogiang']);
												}
												foreach ($id_trogiang AS $key => $val){
													$name_alias = $this->Users[$val]['name'];
													if($this->Users[$val]['alias'] != ''){
														$name_alias = $this->Users[$val]['name'] . ' (' . $this->Users[$val]['alias'] . ')';
													}
													echo '<span class="item goc3" id="'.$this->Users[$val]['id'].'" title="'.$this->Users[$val]['chucvu_name'].' - '.$this->Users[$val]['phongban_name'].'">'.$name_alias.'<a href="javascript:void(0)" class="delete" title="Xóa" onclick="xoaMotUser('.$this->Users[$val]['id'].', \'divChonTroGiang\')"></a></span>';
													echo '<input id="'.$this->Users[$val]['id'].'" type="hidden" name="id_trogiang[]" value="'.$this->Users[$val]['id'].'">';
												}
											} 
											?>
										</div>
										<a onclick="showListUser('divChonTroGiang', 'id_trogiang')" href="javascript:void(0)" class="showListUser" id="showListUser">Show</a>
										<a onclick="xoaTrangDiv('divChonTroGiang')" href="javascript:void(0)" class="deleteListUser">Delete</a>
									</td>
								</tr>
								<tr>
									<td class="label">Chọn Coach</td>
									<td>
										<div class="divChonUser" id="divChonCoach">
											<?php
											if(!empty($this->Item['id_coach'])){
												$id_coach = $this->Item['id_coach'];
												if(!is_array($this->Item['id_coach'])){
													$id_coach = explode(',', $this->Item['id_coach']);
												}
												foreach ($id_coach AS $key => $val){
													$name_alias = $this->Users[$val]['name'];
													if($this->Users[$val]['alias'] != ''){
														$name_alias = $this->Users[$val]['name'] . ' (' . $this->Users[$val]['alias'] . ')';
													}
													echo '<span class="item goc3" id="'.$this->Users[$val]['id'].'" title="'.$this->Users[$val]['chucvu_name'].' - '.$this->Users[$val]['phongban_name'].'">'.$name_alias.'<a href="javascript:void(0)" class="delete" title="Xóa" onclick="xoaMotUser('.$this->Users[$val]['id'].', \'divChonCoach\')"></a></span>';
													echo '<input id="'.$this->Users[$val]['id'].'" type="hidden" name="id_coach[]" value="'.$this->Users[$val]['id'].'">';
												}
											} 
											?>
										</div>
										<a onclick="showListUser('divChonCoach', 'id_coach')" href="javascript:void(0)" class="showListUser" id="showListUser">Show</a>
										<a onclick="xoaTrangDiv('divChonCoach')" href="javascript:void(0)" class="deleteListUser">Delete</a>
									</td>
								</tr>
								<tr>
									<td class="label">Nội dung</td>
									<td colspan="3"><?php echo $content;?></td>
								</tr>
							</table>
						</div>
					</div>
				</div>
				<div id="tabs-2">
					<div class="tblForm">
						<div class="tbl_content">
							<table class="tbl2">
								<tr>
									<td class="label">Ngày khai giảng</td>
									<td><?php echo $ngaykhaigiang;?></td>
									
									<td class="label2">Ngày kết thúc</td>
									<td><?php echo $ngayketthuc;?></td>
								</tr>
							</table>
							
							<div id="listLichhocchon"></div>
							<?php
							$id_lichhoc = '0';
							if(!empty($this->Item['id_lichhoc'])){
								if(is_array($this->Item['id_lichhoc'])){
									$id_lichhoc = implode(',', $this->Item['id_lichhoc']);
								}else{
									$id_lichhoc = $this->Item['id_lichhoc'];
								}
							} 
							?>
							<input type="hidden" id="idLichhocDachon" value="<?php echo $id_lichhoc;?>">
							<br>
							<div id="listLichhoc"></div>
							<script type="text/javascript">
								var id_lichhoc = $('#idLichhocDachon').val();
								$('#listLichhocchon').load('<?php echo $this->baseUrl('default/ajax/ajax-lichhocchon/id_lichhoc/');?>' + id_lichhoc);
								str_diadiemhoc = '';
								<?php if(!empty($this->Item['id_diadiemhoc'])){?>
									str_diadiemhoc = '/id_diadiemhoc/' + <?php echo $this->Item['id_diadiemhoc'];?>;
								<?php }?>
								str_phonghoc = '';
								<?php if(!empty($this->Item['id_phonghoc'])){?>
									str_phonghoc = '/id_phonghoc/' + <?php echo $this->Item['id_phonghoc'];?>;
								<?php }?>
								$('#listLichhoc').load('<?php echo $this->baseUrl('default/ajax/ajax-lichhoc/id_lichhoc/');?>' + id_lichhoc + str_diadiemhoc + str_phonghoc);

								function addLichhoc(idItem){
									$('body').append('<div class="loading_page"></div>');
									idLichhocDachon = $('#idLichhocDachon').val() + ',' + idItem;
									$('#idLichhocDachon').val(idLichhocDachon);
									$('#listLichhocchon').load('<?php echo $this->baseUrl('default/ajax/ajax-lichhocchon/id_lichhoc/');?>' + idLichhocDachon);

									str_diadiemhoc = '';
									if($('select#id_diadiemhoc').val() > 0){
										str_diadiemhoc = '/id_diadiemhoc/' + $('select#id_diadiemhoc').val();
									}
									str_phonghoc = '';
									if($('select#id_phonghoc').val() > 0){
										str_phonghoc = '/id_phonghoc/' + $('select#id_phonghoc').val();
									}
									str_thoigian = '';
									if($('select#thoigian').val() > 0){
										str_thoigian = '/thoigian/' + $('select#thoigian').val();
									}
									str_thu = '';
									if($('select#thu').val() > 0){
										str_thu = '/thu/' + $('select#thu').val();
									}
									
									linkAjax = '<?php echo $this->baseUrl('default/ajax/ajax-lichhoc/id_lichhoc/');?>' + idLichhocDachon + str_diadiemhoc + str_phonghoc + str_thoigian + str_thu;
									$('#listLichhoc').load(linkAjax, function(){ $('.loading_page').remove();});
								}

								function xoaLichhoc(idItem){
									$('body').append('<div class="loading_page"></div>');
									var strId = $('#idLichhocDachon').val();
									var arr = new Array();
									var fields = strId.split(',');
									for(var i = 0; i < fields.length; i++){
										if(parseInt(fields[i]) != parseInt(idItem)){
											arr.push(fields[i]);
										}
									}
									var idLichhocDachon = arr.join();
									$('#idLichhocDachon').val(idLichhocDachon);
									$('#listLichhocchon').load('<?php echo $this->baseUrl('default/ajax/ajax-lichhocchon/id_lichhoc/');?>' + idLichhocDachon);

									str_diadiemhoc = '';
									if($('select#id_diadiemhoc').val() > 0){
										str_diadiemhoc = '/id_diadiemhoc/' + $('select#id_diadiemhoc').val();
									}
									str_phonghoc = '';
									if($('select#id_phonghoc').val() > 0){
										str_phonghoc = '/id_phonghoc/' + $('select#id_phonghoc').val();
									}
									str_thoigian = '';
									if($('select#thoigian').val() != '0'){
										str_thoigian = '/thoigian/' + $('select#thoigian').val();
									}
									str_thu = '';
									if($('select#thu').val() > 0){
										str_thu = '/thu/' + $('select#thu').val();
									}
									$('#listLichhoc').load('<?php echo $this->baseUrl('default/ajax/ajax-lichhoc/id_lichhoc/');?>' + idLichhocDachon + str_diadiemhoc + str_phonghoc + str_thoigian + str_thu, function(){ $('.loading_page').remove();});
								}
							</script>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
</div>
<div class="clr"></div>	